----------------------------------
--      Module Declaration      --
----------------------------------

local boss = BB["Constructor & Controller"]
local constructor = BB["Skarvald the Constructor"]
local controller = BB["Dalronn the Controller"]
local mod = BigWigs:New(boss, tonumber(("$Revision: 548 $"):sub(12, -3)))
if not mod then return end
mod.partyContent = true
mod.otherMenu = "Howling Fjord"
mod.zonename = BZ["Utgarde Keep"]
mod.enabletrigger = {constructor, controller} 
mod.guid = 24200
mod.toggleoptions = {"debilitate", "debilitateBar", "bosskill"}

--------------------------------
--       Are you local?       --
--------------------------------

local deaths = 0

--------------------------------
--        Localization        --
--------------------------------

local L = AceLibrary("AceLocale-2.2"):new("BigWigs"..boss)

L:RegisterTranslations("enUS", function() return {
	cmd = "ControllerConstructor",
	debilitate = "Debilitate",
	debilitateBar = "Debilitate Bar",
	debilitateBar_desc = "Show a bar for the duration of the Debilitate.",
	debilitate_desc = "Warn for who is Debilitated.",
	debilitate_message = "Debilitate: %s",
}

end )

L:RegisterTranslations("deDE", function() return {
	cmd = "ConstructorController",
	debilitate = "Entkräften",
	debilitateBar = "Entkräften-Anzeige",
	debilitateBar_desc = "Eine Leiste für die verbleibende Dauer des Entkräftens anzeigen.",
	debilitate_desc = "Warnen wer von Entkräften betroffen ist.",
	debilitate_message = "Entkräften: %s",
}

end )

L:RegisterTranslations("esES", function() return {
}

end )

L:RegisterTranslations("esMX", function() return {
}

end )

L:RegisterTranslations("frFR", function() return {
	cmd = "ConstructorController",
	debilitate = "Débiliter",
	debilitateBar = "Débiliter - Barre",
	debilitateBar_desc = "Affiche une barre indiquant la durée du Débiliter.",
	debilitate_desc = "Prévient quand un joueur subit les effets de Débiliter.",
	debilitate_message = "Débiliter : %s",
}

end )

L:RegisterTranslations("koKR", function() return {
	cmd = "건축가와 감시자",
	debilitate = "쇠약",
	debilitateBar = "쇠약 바",
	debilitateBar_desc = "쇠약이 지속되는 바를 표시합니다.",
	debilitate_desc = "쇠약의 대상자를 알립니다.",
	debilitate_message = "쇠약: %s",
}

end )

L:RegisterTranslations("ruRU", function() return {
	debilitate = "Ослабление",
	debilitateBar = "Полоса Ослабления",
	debilitateBar_desc = "Отображение полосы продолжительности Ослабления.",
	debilitate_desc = "Предупреждать, когда на кого-нибудь накладывается Ослабление.",
	debilitate_message = "%s: ослаблен!",
}

end )

L:RegisterTranslations("zhCN", function() return {
	debilitate = "衰弱",
	debilitateBar = "衰弱计时条",
	debilitateBar_desc = "当衰弱持续时显示计时条。",
	debilitate_desc = "当玩家中了衰弱时发出警报。",
	debilitate_message = "衰弱：>%s<！",
}

end )

L:RegisterTranslations("zhTW", function() return {
	cmd = "控制者/建造者",
	debilitate = "衰弱",
	debilitateBar = "衰弱計時條",
	debilitateBar_desc = "當衰弱持續時顯示計時條。",
	debilitate_desc = "當玩家中了衰弱時發出警報。",
	debilitate_message = "衰弱：>%s<！",
}

end )

----------------------------------
--        Initialization        --
----------------------------------

function mod:OnEnable()
	self:AddCombatListener("UNIT_DIED", "Deaths")
	self:AddCombatListener("SPELL_AURA_APPLIED", "Debilitate", 43650)

	deaths = 0	
end

----------------------------------
--        Event Handlers        --
----------------------------------

function mod:Deaths(_, guid)
	if not self.db.profile.bosskill then return end
	guid = tonumber((guid):sub(-12,-7),16)
	if guid == self.guid or guid == 24201 then
		deaths = deaths + 1
	end
	if deaths == 2 then
		self:BossDeath(nil, self.guid, true)
	end
end

function mod:Debilitate(player, spellId)
	if self.db.profile.debilitate then
		self:IfMessage(L["debilitate_message"]:format(player), "Attention", spellId)
	end
	if self.db.profile.debilitateBar then
		self:Bar(L["debilitate_message"]:format(player), 8, spellId)
	end
end
